package practice;

import java.util.Arrays;
import java.util.PriorityQueue;

/**
 * @Description: https://leetcode.cn/problems/meeting-rooms-ii/
 * @Author Ammar
 * @Create 2023/7/21 21:36
 */
public class _253_会议室II {
    public int minMeetingRooms(int[][] intervals) {
        if (intervals.length == 1) return 1;
        Arrays.sort(intervals, (m1, m2) -> m1[0] - m2[0]);

        PriorityQueue<Integer> heap = new PriorityQueue<>();
        heap.add(intervals[0][1]);

        for (int i = 1; i < intervals.length; i++) {
            if (intervals[i][0] >= heap.peek()) {
                heap.remove();
            }
            heap.add(intervals[i][1]);
        }
        return heap.size();
    }
}
